package com.dada.cn.paimon;

import org.rocksdb.RocksDB;
import org.rocksdb.Options;
import org.rocksdb.SstFileReader;

import java.util.List;

import org.rocksdb.*;

public class ReadSST {
    public static void main(String[] args) {
        // 初始化 RocksDB
        RocksDB.loadLibrary();

        // SST 文件路径
        String sstFilePath = "/opt/soft/flink/rocksdb/job_7b558d735e42a1fdf086cd72f97d3803_op_KeyedProcessOperator_9b7711354d634ca6a9734a43abeb3114__1_1__uuid_9f5fe225-77ab-43a8-9d3c-ad83d958887d/db/000014.sst";

        try (Options options = new Options().setCreateIfMissing(true);
             SstFileReader sstFileReader = new SstFileReader(options)) {

            // 打开 SST 文件
            sstFileReader.open(sstFilePath);

            // 创建迭代器
            try (SstFileReaderIterator iterator = sstFileReader.newIterator(new ReadOptions())) {
                for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) {
                    byte[] key = iterator.key();
                    byte[] value = iterator.value();
                    System.out.println("Key: " + new String(key) + ", Value: " + new String(value));
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
